package com.lin.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;

import com.lin.vo.Admin;

/**
 *  后台:身份限制权力
 * @author manage
 *
 */
@WebFilter(filterName="PlaceFilter",urlPatterns={"/adminjsps/admin/*"})
public class PlaceFilter  implements Filter{
 
	@Override
	public void destroy() {

	}

	@Override
	public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request=(HttpServletRequest)servletRequest;
		Admin admin= (Admin) request.getSession().getAttribute("admin");
		if(admin == null){
			request.setAttribute("msg", "亲,还没登陆捏~");
			request.getRequestDispatcher("/adminjsps/login.jsp").forward(request,servletResponse);
			return;
		}else{
			chain.doFilter(request, servletResponse);
		}
	}

	@Override
	public void init(FilterConfig arg0) throws ServletException {
	}
	
}
